#define _GNU_SOURCE
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
void *thread_handler1(void *arg)
{ 
    int i=0;
    while(i<20)
    {
        i++;
        printf("thread_handler1 %d is running...\n",gettid() );
        sleep(1);
    }
    return NULL;
}

void *thread_handler2(void *arg)
{ 
      int i=0;
    while(i<40)
    {
        i++;
        printf("thread_handler2 %d is running...\n",gettid() );
        sleep(1);
    }
    return NULL;
}



int main(int argc, char const *argv[])
{
    //创建2个线程
    pthread_t thread_id1, thread_id2;
    pthread_create(&thread_id1, NULL, thread_handler1, NULL);
    pthread_create(&thread_id2, NULL, thread_handler2, NULL);
    int i =0;
    // while(1)
    // {   i++;
    //     if(i==5)
    //     {
        
    //         pthread_cancel(thread_id1);
    //     }
    //     sleep(1);
    // }
    pthread_join(thread_id1, NULL);
    printf("thread_id1   end\n");
    pthread_join(thread_id2, NULL);
    printf("thread_id2  end\n");


    return 0;
}
